package pers.zhxu.extNLPM.estimation;

import pers.zhxu.extNLPM.util.Edge;
import pers.zhxu.extNLPM.util.Graph;
import pers.zhxu.extNLPM.util.Vertex;

import java.util.Calendar;
import java.util.List;
import java.util.Map;

public class ExtMeasure {

    @SuppressWarnings("rawtypes")
    public void calcMeasure(Graph graph, Calendar start, int type){
        List<Vertex> vertices = graph.getVertices();
        for(Vertex uVertex: vertices){
            Map<Integer, List> uResult = graph.getNeighbor(uVertex);
            for(int index=0; index < uResult.get(Graph.NEIGHBORS).size(); index++){
                Vertex zVertex = (Vertex) uResult.get(Graph.NEIGHBORS).get(index);
                int zDirection = (Integer) uResult.get(Graph.DIRECTIONS).get(index);
                List<Edge> zEdge = (List<Edge>) uResult.get(Graph.EDGES).get(index);
                Map<Integer, List> zResult = graph.getNeighbor(zVertex);
                for(int index1=0; index1 < zResult.get(Graph.NEIGHBORS).size();index1++){
                    Vertex vVertex = (Vertex) zResult.get(Graph.NEIGHBORS).get(index);
                    int vDirection = (Integer) zResult.get(Graph.DIRECTIONS).get(index);
                    List<Edge> vEdge = (List<Edge>) zResult.get(Graph.EDGES).get(index);
                    if(uVertex==vVertex)
                        continue;
                    int pattern = matchPattern(zDirection, vDirection);
                    float score = NLPM.measureCalc(zEdge, vEdge, start, type);
                    uVertex.addMeasure(vVertex, pattern, score);
                }
            }
        }
    }

    private int matchPattern(int zDirection, int vDirection){
        return zDirection*vDirection-1;
    }
}
